package com.shopnight.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shopnight.entity.ShopIndent;
import com.shopnight.result.ApiResult;
import com.shopnight.service.ShopIndentService;
import com.shopnight.utils.PageUtils;
import com.shopnight.vo.AddIndentVo;
import com.shopnight.vo.IndentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/api/token")
@Api(tags = {"IndentController"},description = "订单业务所需接口")
public class IndentController {
    @Autowired
    ShopIndentService shopIndentService;

    @PostMapping("/addIndent")
    @ApiOperation(value = "添加订单",notes = "总价，地址id，商品id 商品数量")
    public ApiResult addIndent(@ApiParam("{\n" +
            "    \"userId\":100,\n" +
            "    \"prices\":25,\n" +
            "    \"addressId\":2,\n" +
            "    \"goods\":{\n" +
            "        \"orderId\":2,\n" +
            "        \"orderNum\":5\n" +
            "    } \n" +
            "}")
                             @RequestBody AddIndentVo addIndentVo) throws Exception {
        return  shopIndentService.addIndent(addIndentVo);
    }

    @PostMapping("/updateIndent")
    @ApiOperation(value = "更改订单",notes = "必传订单id，可选参数为 地址id  订单总价格 订单状态")
    public  ApiResult UpdateIndent(
            @ApiParam("可选参数为：{\n" +
                    "  \"addressId\": 0,\n" +
                    "  \"prices\": 0,\n" +
                    "  \"indentStatus\": 0\n" +
                    "}")
            @RequestBody ShopIndent shopIndent) throws IOException {
        return  shopIndentService.UpdateIndent(shopIndent) ;
    }

    @PostMapping("/getUserOrderList")
    @ApiOperation(value = "获取用户订单列表",notes = "必传当前页 页码数 可传订单状态  不传状态则用户所有订单")
    public ApiResult getUserOrderList(@ApiParam("参数为：current pageSize indentStatus") @RequestBody Map<String,String> map){
        return   ApiResult.ok(shopIndentService.getUserOrderList(map)) ;
    }

    @PostMapping("/getUserOrderStatusNumber")
    @ApiOperation(value = "获取用户订单状态数量",notes = "无需传参")
    public ApiResult getUserOrderStatusNumber(){
        return  shopIndentService.getUserOrderStatusNumber();
    }


    @PostMapping("/getIndentInfo")
    @ApiOperation(value = "获取订单详细信息",notes = "必传订单id")
    public ApiResult getIndentInfo(@ApiParam("参数为：indentId ") @RequestBody Map<String,Long> map){
        return  shopIndentService.getIndentInfo(map);
    }

    @PostMapping("/snacksOrderList")
    @ApiOperation(value = "网超零食订单列表",notes = "page,limit,订单号，价格区间，用户姓名，用户手机号")
    public ApiResult list(@ApiParam("参数为：page,limit,indentCode,prices,userName,phonenumber")@RequestBody Map<String, Object> params) throws ExecutionException, InterruptedException {

        return shopIndentService.queryPage(params);
    }


}
